package zucc.edu.repay.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import Bean.travel;
import Util.BaseException;
import Util.HibernateUtil;

public class TravelDao {
	public void delTravel(travel travel) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.delete(travel);
		tx.commit();
		
	}
	
	public void addTravel(travel travel) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.save(travel);
		tx.commit();
				
	}
	
	public void updateTravel(travel travel) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.update(travel);
		tx.commit();
		
	}
	
	public travel searchTravel(String travelid) throws BaseException{
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		String hql = "from travel where travelid = '" + travelid + "'";
		Query qry = s.createQuery(hql);
		Object travel = qry.uniqueResult();
		tx.commit();
		return (travel)travel;
	}
	
	public List<travel> serarchAllTravel(){//�������û�
		Session s = HibernateUtil.getSessionFactory().getCurrentSession(); 
		Transaction tx = s.beginTransaction();
        String hql = "from travel";  
        Query query = s.createQuery(hql);  
        List<travel> roles = query.list();  
        tx.commit();
        return roles; 
}
}
